package config

import (
	"log"

	"github.com/go-ini/ini"
)

type AppConfig struct {
	Server   ServerConfig
	Database DatabaseConfig
}

type ServerConfig struct {
	Port string
}

type DatabaseConfig struct {
	Host     string
	Port     string
	User     string
	Password string
	DBName   string
	Charset  string
}

var Config AppConfig

func LoadConfig() {
	cfg, err := ini.Load("config/app.ini")
	if err != nil {
		log.Fatalf("Failed to load app.ini: %v", err)
	}

	Config.Server.Port = cfg.Section("server").Key("Port").String()

	dbSection := cfg.Section("database")
	Config.Database = DatabaseConfig{
		Host:     dbSection.Key("Host").String(),
		Port:     dbSection.Key("Port").String(),
		User:     dbSection.Key("User").String(),
		Password: dbSection.Key("Password").String(),
		DBName:   dbSection.Key("DBName").String(),
		Charset:  dbSection.Key("Charset").String(),
	}
}
